<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2018/9/8
 * Time: 下午1:42
 */

namespace api\controllers;


use api\models\PhotoComment;
use api\models\User;
use yii\helpers\ArrayHelper;

class CommentController extends ARBaseController
{
    public $modelClass = "api\models\PhotoComment";

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['create']);
        return ArrayHelper::merge($actions,[
            'create',
        ]);
    }

    public function actionCreate(){
        $user = User::getUserByToken();
        $model = new PhotoComment();
        if ($model->load(\Yii::$app->request->getBodyParams(),'')){
            $model->uid = $user->id;
            if ($model->save()){
                return $model;
            }else{
                \Yii::$app->response->statusCode = 422;
                $model->validate();
                return ['error'=>$model];
            }
        }else{
            \Yii::$app->response->statusCode = 422;
            $model->validate();
            return ['error'=>$model];
        }
    }


}